package com.ds.client.screen;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

/**
 * start screen, used to show game start messages
 */
public class StartScreen implements Screen{
	
	InitGame game;
	private Stage startStage;
	Image startScreen;
	Image startBtn;
	
	public StartScreen(InitGame initGame){
		game = initGame;
	}

	@Override
	public void dispose() {
		
	}

	@Override
	public void hide() {
		
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void render(float arg0) {
		Gdx.gl.glClearColor(255, 255, 255, 255);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		startStage.draw();
	}

	@Override
	public void resize(int arg0, int arg1) {
		
	}

	@Override
	public void resume() {
		
	}

	@Override
	public void show() {
		startStage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics
				.getHeight(), false);
		initStart();
		
	}
	public void initStart() {
		Texture tex = new Texture(Gdx.files
				.internal("res/startScreen/background.png"));
		startScreen = new Image(new TextureAtlas(
				"res/startScreen/background.pack").findRegion("Backgroud"));

		startBtn = new Image((new TextureRegion(tex, 308, 150, 180, 100)));
		setImagePosition(startScreen, 0, 0);
		setImagePosition(startBtn, 300, 360);
		startBtn.height = 100;
		startBtn.width = 200;
		startStage.addActor(startScreen);
		startStage.addActor(startBtn);
		// it user click start button
		startBtn.setClickListener(new ClickListener() {
			@Override
			public void click(Actor actor, float arg1, float arg2) {
				game.setScreen(game.chooseScreen);
			}
		});
		Gdx.input.setInputProcessor(startStage);
		
		Music start = Gdx.audio.newMusic(Gdx.files.internal("res/music/start.mp3"));
		start.play();

	}
	public void setImagePosition(Image image, float x, float y) {
		image.x = x;
		image.y = y;
	}

}
